package gatperdut.chato.core.interpreter.actions.generic;

import gatperdut.chato.constants.CSConstantsCommandResult.CommandExecutionResult;
import gatperdut.chato.core.characters.BaseController;
import gatperdut.chato.core.characters.BotController;
import gatperdut.chato.core.entities.PlayerController;
import gatperdut.chato.core.interpreter.grammar.comminfo.CommandInfo;

public abstract class AdminAction extends Action {

    public enum AdminCheckResult {
        ADMIN(true, null), NOT_ADMIN(false, "You don't have the necessary permissions to perform this action."), BOT(false,
                "Bots are not allowed to perform this action.");

        private final boolean allowed;

        private final String message;

        private AdminCheckResult( boolean allowed, String message ) {
            this.allowed = allowed;
            this.message = message;
        }

        public boolean isAllowed() {
            return allowed;
        }

        public String getMessage() {
            return message;
        }
    };

    public AdminAction( CommandInfo info, BaseController entityController ) {
        super( info, entityController );
    }

    @Override
    public abstract CommandExecutionResult perform();

    public AdminCheckResult checkAdminUser() {
        if ( getEntityController() instanceof BotController ) {
            return AdminCheckResult.BOT;
        }

        if ( ( (PlayerController) getEntityController() ).getPlayer().isAdmin() ) {
            return AdminCheckResult.ADMIN;
        }
        else {
            return AdminCheckResult.NOT_ADMIN;
        }
    }

    @Override
    public boolean interruptsCrafting() {
        return false;
    }

}
